#ifndef JSONRPCREPLY_H
#define JSONRPCREPLY_H


#include <QObject>

#include "jsonrpcmessage.h"

/**
 * @brief The JsonRpcResponseHandler class is a class that handles a response when it shows up. This handler is attached to the request id, then it responds only to unique result with this id.
 * The response can be an error message and in this case the 'onFail()' signal will be triggered otherwise the message contains a result because the request succeeded, then the 'onSuccess()' signal
 * is triggered.
 */
class JsonRpcResponseHandler : public QObject
{
    Q_OBJECT
public:
    JsonRpcResponseHandler(int requestId) { v_registeredId = requestId; }

    int id() const;
    JsonRpcMessage response();

    void processResult(const JsonRpcMessage& message);

Q_SIGNALS:
    void onSuccess();
    void onFailed();

private:
    // The response received by the handler
    JsonRpcMessage v_response;
    int v_registeredId;
};


#endif // JSONRPCREPLY_H
